#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "mygraphicsview.h"

#include <QCheckBox>
#include <QDateTime>
#include <QGraphicsRectItem>
#include <QGraphicsView>
#include <QHBoxLayout>
#include <QLabel>
#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QStandardItemModel>
#include <QTableWidget>
#include <QTimer>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

/*
 * label的显示和移动在 两个串口数据处理函数中
 * label的悬停显示在 事件过滤器里
 */


#define ANCHOR_NUM_MAX 30
#define TAG_NUM_MAX 10
#define Offline_delay 5


class Anchor_Tag
{
public:
    QString Type;
    int Addr;
    float X;
    float Y;
    QString Active;
    int Channel;
    int Led;
    uint32_t timer;
    QLabel *label;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    //变量
        //基站标签相关变量
        int ROW=1;
        int COLUMN=6;
        Anchor_Tag Unit[ANCHOR_NUM_MAX]; //目前此上位机最多可有20个基站
        Anchor_Tag MyTag[TAG_NUM_MAX];


        //TableWidget显示相关变量
        QWidget *cell_widget[ANCHOR_NUM_MAX];
        QHBoxLayout *hLayout[ANCHOR_NUM_MAX];
        QCheckBox *checkBox[ANCHOR_NUM_MAX];

        //串口相关变量
        bool UartOpenFlag = true;
        QSerialPort MySerial; //创建串口对象
        QSerialPortInfo *info=new QSerialPortInfo;
        QByteArray Uart_Buffer;

        //定时器相关变量
        QTimer * timer1 = new QTimer(this);
        QTimer * timer2 = new QTimer(this);

        //时间相关变量
        QDateTime current_date_time =QDateTime::currentDateTime();
        QString current_date = current_date_time.toString("yyyy.MM.dd hh:mm:ss");


        //自定义graphicsView子类,实例化
       // MyGraphicsView *graphicsView = new MyGraphicsView();
        QGraphicsRectItem *m_rectitem = new QGraphicsRectItem();


    //函数
    void Unit_Widget_Init(void);
    void Tag_Widget_Init(void);
    void Unit_Data_Deal(int Anchor_Num);
    void Tag_Data_Deal(int Tag_Num);
    void Search_Uart();
    void Uart_Data_Deal(QString input);
    void Uart_Data_Deal__(QString input);
    void Select_Anchor(int num);

private:
    Ui::MainWindow *ui;

    QString TempIndex[ANCHOR_NUM_MAX];
    QString TempAddr[ANCHOR_NUM_MAX];
//    QString X[ANCHOR_NUM_MAX];
//    QString Y[ANCHOR_NUM_MAX];

private slots:
    void Uart_CallBack();
    void TIM1_IQ_Handle();
    void TIM2_IQ_Handle();
    void on_uart_search_button_clicked();
    void on_uart_open_button_clicked();
    void on_pushButton_clicked();

    // QObject interface
    void on_Search_UWB_clicked();

    void on_draw_track_clicked();

    void on_data_track_clicked();

    void on_clear_track_clicked();

public:
    bool eventFilter(QObject *watched, QEvent *event);

    // QWidget interface
protected:
    void resizeEvent(QResizeEvent *event);

    // QWidget interface
protected:
    void paintEvent(QPaintEvent *event);
};
#endif // MAINWINDOW_H
